﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for CommentDAL
/// </summary>
public class CommentDAL
{
    DataAccess acc = new DataAccess();
    public CommentDAL()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    internal DataTable getAllComment()
    {
        return acc.executeSelect("getAllComment");
    }


    internal DataTable getCommentById(int id)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("@Comment_ID", SqlDbType.Int);
        paraList[0].Value = id;
        return acc.executeSelect("getCommentById", paraList);
    }

    internal DataTable getCommentByEmail(string mail)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("@Comment_Mail", SqlDbType.NVarChar, 4000);
        paraList[0].Value = mail;
        return acc.executeSelect("getCommentByMail", paraList);
    }

    internal bool insertComment(string mail, string title, string content)
    {
        SqlParameter[] paraList = new SqlParameter[3];
        paraList[0] = new SqlParameter("@Comment_Mail", SqlDbType.NVarChar, 4000);
        paraList[0].Value = mail;
        paraList[1] = new SqlParameter("@Comment_Title", SqlDbType.NVarChar, 4000);
        paraList[1].Value = title;
        paraList[2] = new SqlParameter("@Comment_Content", SqlDbType.NVarChar, 4000);
        paraList[2].Value = content;
        int check = acc.executeModifier("insertComment", paraList);
        if (check > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    internal bool delComment(int id)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("@Comment_ID", SqlDbType.Int);
        paraList[0].Value = id;
        int check = acc.executeModifier("delComment", paraList);
        if (check > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}